#include "CLoadMap.h"
CLoadMap::CLoadMap()
{

	m_nWidths.clear();
	m_nHeights.clear();
	m_vValidMaps.clear();
	m_unCurrentMapIndex = 0;

}
CLoadMap::~CLoadMap()
{

	m_nWidths.clear();
	m_nHeights.clear();
	if(!m_vValidMaps.empty())
		m_vValidMaps.clear();

}
bool CLoadMap::readBinFile(char *szFile)
{
	std::fstream freader(szFile,std::ios_base::in|std::ios_base::binary);

	int w = 0;
	int h = 0;
	freader.read((char*)&w,sizeof(int));
	freader.read((char*)&h, sizeof(int));

	if(w == 0 && h == 0)
		return false;

	m_nHeights[m_unCurrentMapIndex] = h;
	m_nWidths[m_unCurrentMapIndex] = w;

	int user1 = 0;
	int user2 = 0;
	int user3 = 0;
	int user4 = 0;
	int user5 = 0;

	int y = 0;
	while(y < h)
	{
		int x = 0;
		while(x < w)
		{
			freader.read((char*)&user1,sizeof(int));
			freader.read((char*)&user2,sizeof(int));
			freader.read((char*)&user3,sizeof(int));
			freader.read((char*)&user4,sizeof(int));
			freader.read((char*)&user5,sizeof(int));
			Mappy map;
			map.nX = x;
			map.nY = y;
			map.bCollect = false;
			map.bCollidable = false;
			map.bStart = false;
			map.nExtend = 0;
			map.bHorizontal = false;
			if(user1 != 0)
			{
				map.bCollidable = true;
			}
			if(user2 != 0)
			{
				map.bCollect = true;
			}
			if(user3 != 0)
			{
				map.bStart = true;
			}
			if(user4 != 0)
			{
				map.nExtend = user4;
			}
			if(user5 != 0)
			{
				map.bHorizontal = true;
			}
			if(map.bCollect == true || map.bCollidable == true|| map.bStart == true)
			if(map.bCollidable == true)
			{
				m_vValidMaps[m_unCurrentMapIndex].push_back(map);
			}
			x++;
		}
		y++;
	}
	freader.close();
	freader.clear();
	return true;
}